package com.ruoyi.common.utils.uuid;


import cn.hutool.core.lang.Snowflake;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class NumsUtils {
    private static final Snowflake SNOWFLAKE = new Snowflake(1, 1); // workerId, datacenterId

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");


    public static String generateCode(String prefix) {
        long id = SNOWFLAKE.nextId(); // 假设 SNOWFLAKE 已定义
        LocalDateTime now = LocalDateTime.now();

        // 格式化时间为: yyyyMMddHHmmss (14位)
        String timePart = now.format(FORMATTER); // 例如: 20250514210565

        // 取雪花ID的后9位作为序列号，不足9位前面补0
        String seqPart = String.format("%09d", id % 1000000000L);

        return prefix + timePart + seqPart;
    }
}
